package com.wdc.回溯;

import java.util.*;

@SuppressWarnings("all")
public class E08Leetcode78 {
    private List<List<Integer>> result = new ArrayList<>();
    private LinkedList<Integer> path = new LinkedList<>();

    public List<List<Integer>> subsets(int[] nums) {

        backtracking(nums,0);
        return result;
    }

    void backtracking(int[] nums , int startIndex){
        result.add(new ArrayList<>(path));
        //结束条件
        if (startIndex >= nums.length){
            return;
        }

        //循环求宽度
        for (int i = startIndex; i < nums.length; i++) {
            path.add(nums[i]);
            //递归求深度
            backtracking(nums,i + 1);
            //回溯
            path.removeLast();
        }

    }
}
